package edu.hawaii.ics414.blackjack.player;

import edu.hawaii.ics414.blackjack.card.Card;
import edu.hawaii.ics414.blackjack.card.GameDeck;

/**
 * The most basic computer AI.
 * Continues to hit until reaching 21.
 * 
 * @author Branden Ogata
 *
 */

public class BeginnerPlayer extends AIPlayer
{
  /**
   * Creates a new BeginnerPlayer.
   * 
   * @param money The int equal to the starting amount of money for the new BeginnerPlayer.
   * 
   */
  
  public BeginnerPlayer(int money)
  {
    super(money);
  }
  
  /**
   * Returns the move of this BeginnerPlayer.
   * 
   * @param deck The GameDeck containing the cards to use.
   * @param hand The int indicating the hand to play on.
   * @param hole The Card that the dealer has showing.
   *
   * @return action The Action that this BeginnerPlayer intends to play.
   * 
   */
  
  @Override
  public Action getMove(GameDeck deck, int hand, Card hole)
  {
    Action action = Action.STAND;
    
    // If a split is valid, then do so
    if (this.canSplit(hand) && this.canBet(this.getBet(hand)))
    {
      action = Action.SPLIT;
    }
    
    // Else if less than 21, then hit
    else if (this.canHit(hand))
    {
      action = Action.HIT;
    }
    
    return action;
  }

  /**
   * Starts a new hand with an initial bet of 10.
   * 
   * @param deck The GameDeck to take cards from.
   * 
   */
  
  @Override
  public void startHand(GameDeck deck)
  {
    this.setBet(0, (int) (Math.random() * 100 + 1));
    super.startHand(deck);
  }
  
  /**
   * Returns a String representation of the cards for this BeginnerPlayer.
   * This should show the cards face down.
   * 
   * @return desc A String representing the cards that this BeginnerPlayer has.
   * 
   */
  
  @Override
  public String getCards()
  {
    String desc = "";
    int i = 0;
    // For each hand
    for (Card[] hand : this.hands)
    {
      //prints the value and bet for the hand as well.
      if (hand[0] != null)
      {
        desc += "(Bet: ";
        desc += this.getBet(i);
        desc += ") ";
        desc += "Hand ";
        desc += (i + 1);
        desc += ": (Value: ";
        desc += handValue(i);
        desc += ")  -  ";
      }
      // Add each card to the String
      for (Card card : hand)
      {
        if (card != null)
        {
          desc += card + " ";
        }
      }
      
      if (hand[0] != null)
      {
        desc += "\n";
      }
      i++;
    }
    
    return desc;
  }
}